
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title></title>
	<link href="../css/layui.css" rel="stylesheet" media="all">
</head>
<body>
<div class="demoTable" id="yc-find">
	<label>用户名</label>
	<div class="layui-input-inline">
		<input type="text" name="nickName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input"/>
	</div>
	<button type="button" class="layui-btn layui-btn-warm" id="do_search" >查询</button>
</div>
<div class="layui-row" id="updateTest" style="display:none;" >
	<div class="layui-col-md10">
		<form class="layui-form layui-from-pane" lay-filter="edit" action="" style="margin-top:20px" >
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">权限</label>
					<div class="layui-input-inline">
						<select name="status"  lay-verify="required" lay-search>
							<option value="1">未发货</option>
							<option value="2">已发货</option>
							<option value="3">已到达</option>
						</select>
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">订单状态</label>
					<div class="layui-input-inline">
						<input type="text" name="invoice" id="inputId" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" readonly>
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button type="button" class="layui-btn" id="add_btn" lay-submit lay-filter="demo11">提交修改</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</div>
</div>
<table class="layui-hide" id="test" lay-filter="test"></table>
<script type="text/html" id="barDemo">
	<div class="layui-clear-space">
		<a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
	</div>
</script>
<script src="../js/jquery-3.4.1.min.js"></script>
<script src="../js/layui.js" charset="utf-8"></script>
<script src="../js/axios.js"></script>
<script>
	layui.use(['table','form'],function() {
		var table = layui.table;
		var form=layui.form;

		table.render({
			elem: '#test',
			url: '../../order?op=findAll01',
			toolbar: 'default',
			title: '订单信息表',
			cellMinWidth: 120,
			id: 'test',
			page: true,
			page: {limits: [3, 5, 7]},

			cols: [[
				{type: 'checkbox', fixed: 'center'},
				{field: 'ono', title: '订单号', fixed: 'center', unresize: true, sort: true, align: 'center'},
				{field: 'odate', title: '下单时间', fixed: 'center', align: 'center',sort: true,width:200},
				{field: 'nickName', title: '用户名', fixed: 'center', align: 'center'},
				{field: 'name', title: '昵称', fixed: 'center', align: 'center'},
				{field: 'addr', title: '地址', fixed: 'center', align: 'center'},
				{field: 'status', title: '物流状态', fixed: 'center', align: 'center',sort: true,templet: function (data) {
						if (data.status=="3"){
							return "已送达"
						}else if (data.status=="2"){
							return "已发货"
						}else if (data.status=="1"){
							return "未发货"
						}
					}},
				{field: 'invoice', title: '订单状态', fixed: 'center', align: 'center',sort: true,templet: function (data) {
						if (data.invoice == "1") {
							return "已支付"
						} else if (data.invoice == "0") {
							return "未支付"
						}else {
							return "异常"
						}
					}},
				{field: 'aa', title: '操作', templet: "#barDemo"}
			]]
		});
		table.on('tool',function (obj) {
			var data = obj.data;
			console.log(obj);
			if (obj.event == 'edit') {
				layer.open({
					//layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
					id: 'update',
					type: 1,
					title: "修改商品信息",
					area: ['50%', '90%'],
					content: $("#updateTest"),//引用的弹出层的页面层的方式加载修改界面表单

					success: function (msg) {
						console.log(msg);

						form.val("edit", data);
						//表单数据回显
						console.log(data.invoice);
						if (data.invoice === 1) {
							$("#inputId").val("已支付");
						} else if (data.invoice === 0) {
							$("#inputId").val("未支付");
						} else {
							$("#inputId").val("未知状态");
						}
					},

				});
				setOrder(obj,data);
			}

		});

		$('#do_search').on('click', function () {
			// 搜索条件
			var name = $('#yc-find input[name="nickName"]').val();
			console.log(name);
			table.reload('test', {
				method: 'post', where: {
					nickName: name
				}
				, page: {
					curr: 1
				}
			});


		});
		function setOrder(obj,data) {
			console.log(data);
			if (data.invoice=="0"){
				alert("订单未支付！")
				layer.close('update');
				table.reload('test',{  //表格重载，刷新数据 test是数据表格的id
					url:'../../order?op=findAll01',
					page: {
						curr:1
					}
				});
			}
			form.on('submit(demo11)', function (massage) {
				$.ajax({
					url: '../../order?op=update',
					type: 'POST',
					data: {
						status:massage.field.status,
						invoice :data.invoice,
						ono:data.ono,
					},
					success: function (msg) {
						if (msg == "1" && data.status == "1" ){
							alert("发货成功");
							layer.close('update');
							table.reload('test',{  //表格重载，刷新数据 test是数据表格的id
								url:'../../order?op=findAll01',
								page: {
									curr:1
								}
							});
						}else if (msg == "1" && data.status == "2" ){
							alert("已送达");
							layer.close('update');
							table.reload('test',{  //表格重载，刷新数据 test是数据表格的id
								url:'../../order?op=findAll01',
								page: {
									curr:1
								}
							});
						}else if (msg == "1" && data.status == "3" ){
							alert("已修改");
							layer.close('update');
							table.reload('test',{  //表格重载，刷新数据 test是数据表格的id
								url:'../../order?op=findAll01',
								page: {
									curr:1
								}
							});
						}

					}
				});
			});
		}

	});
</script>
</body>
</html>